<?php
declare(strict_types=1);
 
namespace App\JsonRpc\ServiceProvider;

use App\Constants\ErrorCode;
use App\Dao\AdminLogDao;
use App\Validate\LogRpcValidation;
use Hyperf\RpcServer\Annotation\RpcService;
use App\Utils\ServerUtil;
use App\Utils\ApiUtils;
use Hyperf\Utils\ApplicationContext;

/**
 * 注意，如希望通过服务中心来管理服务，需在注解内增加 publishTo 属性
 * @RpcService(name="LogService", protocol="jsonrpc", server="jsonrpc")
 */
class LogService implements CouponServiceInterface
{
    public function consume($data): string{
        $data = json_decode($data,true); 
        ServerUtil::info('rpc-LogService-进入', ['param'=>$data]);

        $obj = ApplicationContext::getContainer()->get(AdminLogDao::class);
        ApplicationContext::getContainer()->get(LogRpcValidation::class)->check($data, 'log')->response();

        $obj->addLog($data['log'], $data['admin_id']);
        $responseData=json_encode(ApiUtils::send(ErrorCode::SUCCESS,'操作成功'));
        ServerUtil::info('rpc-LogService-退出', ['param'=>$data,'res'=>$responseData]);
        return $responseData;
    }
}
